<?php 

add_action('admin_menu', 'add_option_interface');
add_action('admin_post_saveoptions', 'saveoptions');

function saveoptions(){

	//NEW 
	$pagelines = new Options;
	
	if($_POST['restore']){
		
		$pagelines->restore_options();
		wp_redirect(admin_url('themes.php?page=functions&restored=true'));
		
	}else{
		
		$pagelines->update_option('custom_header');	
		$pagelines->update_option('rsslink');
		$pagelines->update_option('facebooklink');
		$pagelines->update_option('twitterlink');
		$pagelines->update_option('twittername');
		$pagelines->update_option('linkedinlink');	

		$pagelines->update_option('customcss');
		$pagelines->update_option('headerscripts');
		$pagelines->update_option('footerscripts');
		
		// color
		$pagelines->update_option('colorscheme');
		$pagelines->update_option('backgroundcolor');
		$pagelines->update_option('headercolor');
		$pagelines->update_option('linkcolor');
		$pagelines->update_option('metacolor');
		$pagelines->update_option('metacolortext');
		$pagelines->update_option('metacolorlink');
		
		// layout
		$pagelines->update_option('grandnav');
		$pagelines->update_option('pagetitles');	
		// sidebar 
		$pagelines->update_option('showads');
		$pagelines->update_option('adslink');
	
		//posts
		$pagelines->update_option('authorinfo');
		$pagelines->update_option('excerpts');
		$pagelines->update_option('excerptshide');
		$pagelines->update_option('excerptshidesingle');
	
		// footer 
		$pagelines->update_option('bottom_sidebars');
		$pagelines->update_option('footnav');
		$pagelines->update_option('terms');
	
		$pagelines->update_option('favicon');
		$pagelines->update_option('touchicon');
		$pagelines->update_option('greeting');
		$pagelines->update_option('welcomemessage');
	
		$pagelines->update_option('debug');
	
	
		$pagelines->save_options();
	
		wp_redirect(admin_url('themes.php?page=functions&updated=true'));
	}
}
function add_option_interface() {
  add_theme_page(THEMENAMESHORT.' Options', THEMENAMESHORT.' Options', '8', 'functions', 'editoptions');
}
function editoptions() { ?> 
					
<style>
.admin_icon {float: left;margin:0px 5px 20px 0px;}
.pro {background: #eee}
.tpro {color: #999;}
</style>
<div class='wrap'>
  <h2><?php echo THEMENAME;?> Options</h2>
  <form method="post" action="<?php echo admin_url('admin-post.php?action=saveoptions'); ?>">
	  <?php wp_nonce_field('update-options') ?>	
	
			<?php if($_GET['updated']=='true'):?>
					<div id="message" class="updated fade" style="background-color: rgb(255, 251, 204);">
						<p>	<strong>Options Saved.</strong></p>
					</div>
			<?php endif;?>
			<?php if($_GET['restored']=='true'):?>
					<div id="message" class="updated fade" style="background-color: rgb(255, 251, 204);">
						<p>	<strong>Options Restored To Default.</strong></p>
					</div>
			<?php endif;?>
			<?php if(floatval(phpversion()) < 5.0):?>
			<div id="message" class="updated fade" style="background-color: rgb(255, 251, 204);">	
			<p><strong>You are using PHP version <?php echo phpversion(); ?>.</strong>  Version 5 or higher is required for this theme to work correctly.</p>  <p>Please check with your host about upgrading to a newer version.</p> 
			</div>
			<?php endif;?>
			<p></a>Welcome to <?php echo THEMENAME;?> Options. We hope your enjoying this theme from <a href="http://www.pagelines.com">PageLines</a>.</p>
			
			<?php if(!VPRO):?><p><a href="http://www.pagelines.com/themes/whitehousepro" title="White House Pro"><img alt="" src="http://www.pagelines.com/images/advert3.png" class="alignright"/></a> This is the Basic version of WhiteHouse. If you would like CMS features, tons more options &amp; templates and support, please visit our site to learn about <a href="http://www.pagelines.com/themes/whitehousepro">WhiteHouse Pro</a></p><?php else:?><a href="http://www.pagelines.com" title="PageLines"><img alt="PageLines Themes" src="<?php echo IMAGE_FOLDER;?>/pagelines.png" class="alignright"/></a><?php endif;?>
			
			<p>This section allows you to customize your theme, if any options are empty or unchecked they won't be shown. <br/><small><em>Note:</em> PHP 5 is required for options to work. If you would like to use <strong>custom</strong> images you will need to have their direct URL addresses available.</small></p>

			<table class="form-table">
				<tbody>
					<tr valign="top">
						<th scope="row"><strong>Custom Header Image</strong><br/><small>Input Full URL to your custom header or logo image.</small></th>
						<td><input class="regular-text" type="text" name="custom_header" value="<?php echo pagelines('custom_header'); ?>" /><br/>
							<span class="setting-description">Optional way to replace 'heading' and 'description' text for your website with an image.</span>
							<?php if(pagelines('custom_header')):?>
								<p><img src="<?php echo pagelines('custom_header');?>" style="width:200px; "/></p>
							<?php endif;?>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row"><strong>Favicon Image</strong><br/><small>Input Full URL to Favicon</small></th>
						<td><input class="regular-text" type="text" name="favicon" value="<?php echo pagelines('favicon'); ?>" /><br/>
							<span class="setting-description">Enter the full URL location of your custom 'favicon' which is visible in browser favorites and tabs (typically called favicon.ico ). </span>
							<?php if(pagelines('favicon')):?>
								<p><strong>Current favicon:</strong> <img src="<?php echo pagelines('favicon');?>"/></p>
							<?php endif;?>
						</td>
					</tr>
				
					<?php if(VPRO):?>
					<tr valign="top" class="pro">
						<th scope="row"><strong>Apple Touch Image <span class="tpro">(pro)</span></strong><br/><small>Input Full URL to Touch Icon (iPhones, iPods)</small></th>
						<td><input class="regular-text" type="text" name="touchicon" value="<?php echo pagelines('touchicon'); ?>" /><br/>
							<span class="setting-description">Enter the full URL location of your Apple Touch Icon which is visible when used as a <strong>webclip</strong> in Apple Iphone and Touch Products (approximately 57px by 57px).</span>
							<?php if(pagelines('touchicon')):?>
								<p><strong>Current Icon:</strong> <img src="<?php echo pagelines('touchicon');?>"/></p>
							<?php endif;?>
						</td>
					</tr>
					<?php endif;?>
					<tr valign="top" class="allow">
						<th scope="row"><strong>Welcome Heading</strong><br/><small>Insert your welcome greeting. Shows on main 'blog' page.</small></th>
	 					<td><textarea name="greeting" cols="60" rows="2"><?php echo pagelines('greeting'); ?></textarea>
							<span class="setting-description"></span>
						</td>
					</tr>
					<tr valign="top" class="allow">
						<th scope="row"><strong>Welcome Message</strong><br/><small>Insert your HTML formatted welcome message. Shows on main 'blog' page.</small></th>
	 					<td><textarea name="welcomemessage" cols="60" rows="3"><?php echo pagelines('welcomemessage'); ?></textarea>
							<span class="setting-description"></span>
						</td>
					</tr>
				</tbody>
			</table>	
			<div>
				<br />
				<h3>Color Preferences</h3>
				<p>This section allows you to customize the color of elements like links.</p>
			</div>
			<table class="form-table">
				<tbody>
					
					<?php if(VPRO):?>
					<tr valign="top" class="pro">
						<th scope="row"><strong>Color Scheme <span class="tpro">(pro)</span></strong><br/><small>Select your site color scheme</small></th>
						<td>
							<input type="radio" name="colorscheme" value="blue" <?php if(pagelines('colorscheme') != 'black'):?>checked<?php endif;?>> Blue<br/>
							<input type="radio" name="colorscheme" value="black" <?php if(pagelines('colorscheme') == 'black'):?>checked<?php endif;?>>
							Black

						</td>
					</tr>
					<?php endif; ?>
					<?php if(VPRO):?>
					<tr valign="top" class="pro">
						<th scope="row"><strong>Post Meta Color<span class="tpro">(pro)</span></strong><br/><small>The color of the bar with category, date, and author in posts.</small></th>
						<td>
							<label>Bar Color Hex Code: </label><input id="metacolor" size="7"  type="text" name="metacolor" value="<?php echo pagelines('metacolor'); ?>" /><span class="setting-description"></span><br/>
							<label>Bar Text Color Hex Code: </label><input id="metacolor" size="7"  type="text" name="metacolortext" value="<?php echo pagelines('metacolortext'); ?>" /><span class="setting-description"></span><br/>
							<label>Bar Link Color Hex Code: </label><input id="metacolor" size="7"  type="text" name="metacolorlink" value="<?php echo pagelines('metacolorlink'); ?>" /><span class="setting-description"></span>
						</td>
					</tr>
					<?php endif; ?>
					<tr valign="top" class="allow">
						<th scope="row"><strong>Link Color</strong><br/><small>This option will change color of your site's links and similar items.</small></th>
						<td>
							<label>Hex Code: </label><input id="bgcolor" size="7"  type="text" name="linkcolor" value="<?php echo pagelines('linkcolor'); ?>" /><span class="setting-description"> Default is #005299</span>
						</td>
					</tr>
					<?php if(VPRO):?>
					<tr valign="top" class="pro">
						<th scope="row"><strong>Text Header Color <span class="tpro">(pro)</span></strong><br/><small>This option will change color of your text headers.</small></th>
						<td>
							<label>Hex Code: </label><input id="bgcolor" size="7"  type="text" name="headercolor" value="<?php echo pagelines('headercolor'); ?>" /><span class="setting-description"> Default is #000000 (black)</span>
						</td>
					</tr>
					<?php endif;?>
					<?php if(VPRO):?>
					<tr valign="top" class="pro">
						<th scope="row"><strong>Background <span class="tpro">(pro)</span></strong><br/><small>This option will change color or image in your site background.</small></th>
						<td>
							<label>Hex Code or background CSS: </label><input id="bgcolor" size="20"  type="text" name="backgroundcolor" value="<?php echo pagelines('backgroundcolor'); ?>" /><br/><span class="setting-description"> If you really want to, you can change the theme background here. It will remove the current image and color. It's possible to use something like "#666666 url(my_image_url) no-repeat 0 0" or just a hex color.</span>
						</td>
					</tr>
					<?php endif;?>
				</tbody>
			</table>
				<div>
					<br />
					<h3>Page/Post Options</h3>
					<p>This section allows you to customize elements on posts or pages.</p>
				</div>
				<table class="form-table">
					<tbody>
		
						<tr valign="top">
							<th scope="row"><strong>Twitter Latest Entry</strong><br/><small>This option will place your latest Twitter entry in the subhead for your blog, search, and single-post pages.</small></th>
							<td>
								<label>Username </label><input id="bgcolor" size="20"  type="text" name="twittername" value="<?php echo pagelines('twittername'); ?>" /><span class="setting-description">Enter your twitter username</span>
							</td>
						</tr>
						<?php if(VPRO):?>
						<tr valign="top" class="pro">
							<th scope="row"><strong>Grandchild Nav <span class="tpro">(pro)</span></strong><br/><small>If you have grandchildren pages, a special navigation will show up on second-tier pages with a third-tier navigation.</small></th>
							<td>
								<input class="admin_checkbox" type="checkbox" name="grandnav" <?php if(pagelines('grandnav')) echo 'checked'; else echo 'unchecked';?> /> <label for="pagetitles">Show grandchild navigation? </label>
							</td>
						</tr>
						<?php endif;?>
						<?php if(VPRO):?>
						<tr valign="top" class="pro">
							<th scope="row"><strong>Page Titles <span class="tpro">(pro)</span></strong><br/><small>Adding default WP titles to all your pages can be annoying. Use this to turn this off.</small></th>
							<td>
								<input class="admin_checkbox" type="checkbox" name="pagetitles" <?php if(pagelines('pagetitles')) echo 'checked'; else echo 'unchecked';?> /> <label for="pagetitles">Show WP titles on Pages? </label>
							</td>
						</tr>
						<?php endif;?>
						
						<?php if(VPRO):?>
							<tr valign="top" class="pro">
								<th scope="row"><strong>Author Info <span class="tpro">(pro)</span></strong></th>
								<td>
									<label>Show author info in posts? </label><input class="admin_checkbox" type="checkbox" name="authorinfo" <?php if(pagelines('authorinfo')) echo 'checked'; else echo 'unchecked';?> />
								</td>
							</tr>
							<tr valign="top" class="pro">
								<th scope="row"><strong>Excerpts <span class="tpro">(pro)</span></strong></th>
								<td>
									<label>Show only excerpts &amp; thumbs on front page instead of full posts? </label><input class="admin_checkbox" type="checkbox" name="excerpts" <?php if(pagelines('excerpts')) echo 'checked'; else echo 'unchecked';?> />
								</td>
							</tr>
							<tr valign="top" class="pro">
								<th scope="row"><strong>Hide Excerpts <span class="tpro">(pro)</span></strong></th>
								<td>
									<label>Hide excerpts completely in the theme? </label><input class="admin_checkbox" type="checkbox" name="excerptshide" <?php if(pagelines('excerptshide')) echo 'checked'; else echo 'unchecked';?> />
								</td>
							</tr>
							<tr valign="top">
								<th scope="row"><strong>Hide Excerpts &amp; Thumbs In Single Posts?</strong></th>
								<td>
									<label>Hide excerpts and thumbs when users are viewing individual posts? </label><input class="admin_checkbox" type="checkbox" name="excerptshidesingle" <?php if(pagelines('excerptshidesingle')) echo 'checked'; else echo 'unchecked';?> />
								</td>
							</tr>
						<?php endif;?>
						<?php if(VPRO):?>
						<tr valign="top" class="pro">
							<th scope="row"><strong>Site Terms <span class="tpro">(pro)</span></strong><br/><small>This option will add a line of text to your footer that can be used to add a copyright and links to a sitemap, or terms.</small></th>
							<td>
								<input id="bgcolor" size="40"  type="text" name="terms" value="<?php echo pagelines('terms'); ?>" /><br/><span class="setting-description">Enter your site footer line.</span>
							</td>
						</tr>
						<?php endif;?>
						<tr valign="top" class="allow">
							<th scope="row"><strong>Footer Navigation</strong></th>
							<td>
								<input class="admin_checkbox" type="checkbox" name="footnav" <?php if(pagelines('footnav')) echo 'checked'; else echo 'unchecked';?> /> <label>Show footer navigation (mirrors top navigation)? </label>
							</td>
						</tr>
						<?php if(VPRO):?>
						<tr valign="top" class="pro">
							<th scope="row"><strong>Footer Sidebars <span class="tpro">(pro)</span></strong></th>
							<td>
								<input class="admin_checkbox" type="checkbox" name="bottom_sidebars" <?php if(pagelines('bottom_sidebars')) echo 'checked'; else echo 'unchecked';?> /> <label>Show footer sidebars? </label>
							</td>
						</tr>
						<?php endif;?>
						<?php if(VPRO):?>
						<tr valign="top" class="pro">
							<th scope="row"><strong>Show Ads <span class="tpro">(pro)</span></strong></th>
							<td>
								<input class="admin_checkbox" type="checkbox" name="showads" <?php if(pagelines('showads')) echo 'checked'; else echo 'unchecked';?> /> <label>Create a position for ads in sidebar? </label>
								<p>If you are using the <a href="http://wordpress.org/extend/plugins/ad-minister/">'ad-minister' plugin</a>, then you will need a theme that has placed a 'position' for ads in the theme.  By selecting this, you add a position on top of the sidebar for your ads.</p><p><small>Call your position 'Small Banner' (capitalized) and when creating content use images sized to <strong>125px by 125px</strong>.</small></p>
								<p>Want a "learn more about advertising" link under your ads? <br/>
									<input id="bgcolor" size="40"  type="text" name="adslink" value="<?php echo pagelines('adslink'); ?>" /><br/><span class="setting-description">Enter your 'more information' permalink.</span></p>
							</td>
						</tr>
						<?php endif;?>
					</tbody>
				</table>
			
			
			<div>
				<br />
				<h3>Header Icon Options</h3>
				<p>This section allows you to choose which options appear on your pages.</p>
			</div>
				<table class="form-table">

					<tbody>
						<tr valign="middle">
							<th scope="row">
								<img class="admin_icon" src="<?php echo IMAGE_FOLDER; ?>/rssicon.png" alt="icon"/>
								<strong>RSS</strong><br/><small>Display the RSS icon and link?</small>
							</th>
							<td>
								<input class="admin_checkbox" type="checkbox" name="rsslink" <?php if(pagelines('rsslink')):
								echo 'checked'; else: echo 'unchecked'; endif;?> />
							</td>
						</tr>
						<?php if(VPRO):?>
						<tr valign="middle" class="pro">
							<th scope="row">
								<img class="admin_icon" src="<?php echo IMAGE_FOLDER; ?>/facebookicon.png" alt="icon"/>
								<strong>Facebook <span class="tpro">(pro)</span></strong><br/><small>Display the Facebook icon and link?</small>
							</th>
							<td>
									<input class="icon_input" name="facebooklink" type="text" size="50" value="<?php echo pagelines('facebooklink') ?>"/>
									<span class="setting-description">Enter the full link to your Facebook profile</span>
							</td>
						</tr>
						<?php endif;?>
						<?php if(VPRO):?>
						<tr valign="middle" class="pro">
							<th scope="row">
								<img class="admin_icon" src="<?php echo IMAGE_FOLDER; ?>/twittericon.png" alt="icon"/>
								<strong>Twitter <span class="tpro">(pro)</span></strong><br/><small>Display the Twitter icon and link?</small>
							</th>
							<td>
								
									<input class="icon_input" name="twitterlink" type="text" size="50" value="<?php echo pagelines('twitterlink') ?>"/>
									<span class="setting-description">Enter the full link to your Twitter profile</span>
							</td>
						</tr>
						<?php endif;?>
						<?php if(VPRO):?>
						<tr valign="middle" class="pro">
							<th scope="row">
								<img class="admin_icon" src="<?php echo IMAGE_FOLDER; ?>/linkedinicon.png" alt="icon"/>
								<strong>LinkedIn <span class="tpro">(pro)</span></strong><br/><small>Display the LinkedIn icon and a Profile link?</small>
							</th>
							<td>
								<div class="icon_link">
									<input class="icon_input" name="linkedinlink" type="text" size="50" value="<?php echo pagelines('linkedinlink') ?>"/>
									<span class="setting-description">Enter the link to your LinkedIn profile</span>
								</div>
							</td>
						</tr>
						<?php endif;?>
						</tbody>
				</table>
	

			
			<h3>Custom Scripts</h3>
			<p>Here is where you can enter your custom scripts</p>
			<table class="form-table">
				<tbody>
					<?php if(VPRO):?>
					<tr valign="top" class="pro">
						<th scope="row"><strong>Custom CSS <span class="tpro">(pro)</span></strong><br/><small>Insert custom CSS styling here (this will override any default styling)</small></th>
	 					<td><textarea name="customcss" cols="60" rows="5"><?php echo pagelines('customcss'); ?></textarea>
							<span class="setting-description">example: <strong>a {color: #555555; }</strong></span>
						</td>
					</tr>
					<?php endif;?>
					<?php if(VPRO):?>
					<tr valign="top" class="pro">
						<th scope="row"><strong>Header Scripts <span class="tpro">(pro)</span></strong><br/><small>Enter any special header scripts here (inserted before end of head tag)</small></th>
	 					<td><textarea name="headerscripts" cols="60" rows="5"><?php echo pagelines('headerscripts'); ?></textarea>
							<span class="setting-description"></span>
						</td>
					</tr>
					<?php endif;?>
					<tr valign="top">
						<th scope="row"><strong>Footer Scripts &amp;<br/> Easy Analytics </strong><br/><small>Insert your footer code here, great for adding Google Analytics.</small></th>
	 					<td><textarea name="footerscripts" cols="60" rows="5"><?php echo pagelines('footerscripts'); ?></textarea>
							<span class="setting-description"></span>
						</td>
					</tr>
					<?php if(VPRO):?>
					<tr valign="top" class="pro">
						<th scope="row"><strong>Debug Page Load <span class="tpro">(pro)</span></strong><br/><small>shows page load time in footer.</small></th>
	 					<td>
							<label>Show page load time (debugging)? </label><input class="admin_checkbox" type="checkbox" name="debug" <?php if(pagelines('debug')) echo 'checked'; else echo 'unchecked';?> />
						</td>
					</tr>
					<?php endif;?>
						<tr valign="top" class="">
							<th scope="row"><strong>Questions?</strong></th>
		 					<td>
								<label>Please visit our site at <a href="http://www.pagelines.com">PageLines.com</a> for additional resources, help or information.</label>
							</td>
						</tr>
			</tbody>
			</table>
			<br/>
			
			
	  	  	<input type="hidden" name="action" value="saveoptions" /> <!-- the function we execute to process -->
		  	  <p><input class="button-primary" type="submit" name="Submit" value="Save Options" /></p>
		
				<p>
					Sometimes the options can get tweaked and its best to restore them to their defaults. To do that use this button.
					<script language="jscript" type="text/javascript">
					function ConfirmRestore(){	
						var a = confirm ("Are you sure? This will restore your options to their defaults.");
						if(a) return true;
						else return false;
					}
					</script>
					<input class="button-secondary" type="submit" name="restore" onClick="return ConfirmRestore();" value="Restore Options To Default" />
				</p>
	</div>
  </form>
  </div>
<?php } ?>